package cn.neusoft.controller;


import cn.neusoft.exception.AppException;
import cn.neusoft.exception.AppExceptionCodeMsg;
import cn.neusoft.pojo.Register;
import cn.neusoft.query.RegisterQuery;
import cn.neusoft.service.IRegisterService;
import cn.neusoft.vo.ResultBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hxj
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/register")
public class RegisterController extends BaseController<Register, RegisterQuery>{

    @Autowired
    IRegisterService registerService;

    @ApiOperation("修改挂号状态")
    @PostMapping("/change/state")
    public ResultBean changeState(@RequestBody Register register){

        if (register==null || register.getVisitState()==null || register.getId()==null){
            throw new AppException(AppExceptionCodeMsg.PARAMS_EMPTY);
        }

        UpdateWrapper<Register> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("visit_state",register.getVisitState())
                .eq("id",register.getId());
        boolean update = registerService.update(updateWrapper);
        return update?ResultBean.SUCCESS():ResultBean.ERROR("修改挂号状态失败");
    }

    @ApiOperation("根据病历号查询患者信息")
    @PostMapping("/case/{casenumber}")
    public ResultBean getByConditions(@PathVariable("casenumber")String caseNumber){
        QueryWrapper<Register> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("case_number",caseNumber);

        Register one = registerService.getOne(queryWrapper);
        return one==null?ResultBean.ERROR("患者不存在"):ResultBean.SUCCESS(one);
    }

}
